Skip to content

fix(studio): a sealed preview's reload shows in a fraction of a second, not after 8 s - #8015

Merged
miguel-heygen merged 6 commits into
mainfrom
fix/studio-sealed-reload-renders
Nov 17, 2026
Merged

miguel-heygen merged 6 commits into
mainfrom
fix/studio-sealed-reload-renders

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What

A sealed preview (the preview on an opaque origin, VITE_STUDIO_OPAQUE_PREVIEW_ENABLED) now shows a reload in a fraction of a second. Before, every full reload on a sealed preview (an undo that needs one, a structural edit, a sub-composition change) kept the old picture for about 8.4 s.

A reload loads the new preview in a second frame behind the live one and swaps it in once that frame reports it is ready. That frame was hidden with visibility: hidden and clip-path: inset(100%). Chrome stops rendering a cross-origin frame that is hidden or clipped away, and a sealed frame is cross-origin. Its runtime waits for painted, idle frames before it reports its assets ready, so it got none and reported only when its readiness timeout ran out (8 s), and the player then let the swap happen.

A sealed reload's frame is now transparent instead (opacity: 0), so it keeps rendering out of sight and reports ready as soon as it is. It sits over the live frame, so the reload code (useShadowPreviewReload) makes its player element inert when its frame arrives and clears that at promotion. The player turns pointer events back on for its own frame, and inert takes the player's whole subtree, that frame included, out of hit testing and focus, so clicks and keys still reach the live preview. Player itself is unchanged. A same-origin preview keeps the hidden, clipped frame it had (Chrome renders a same-origin frame either way); its reload frame is inert too, which changes nothing a person can do since it was already hidden.

Why

With the preview sealed, the old picture stayed up for 8 s after an undo or a reload, which reads as the edit not having happened.

What I measured

On a Linux box, against this main, with the sealed default from #7846 applied and Studio's reload stages logged:

  • Before: the reload's frame had its adapter ready 290 ms after the reload began, and its ready-to-show came 8.4 s after that. In the edit accuracy bench's root move case, the undone box was back only after 8.7 s.
  • After, at this head: in a traced bench run of the root and nested move cases, every sealed reload swapped in, 262 and 356 ms after it began (287, 312 and 382 ms in an earlier run of the same style).
  • Clicks, in the Chrome headless shell the bench uses: a transparent sandboxed frame over another, its own frame set back to pointer-events: auto as the player does. Without inert on the covering frame's host element the click lands in the covering frame; with it, the click lands in the frame underneath. Both frames kept animating (61 animation frames in 1 s each), so inert does not stop the hidden frame rendering.
  • An earlier commit on this branch put the frame under the live one (z-index: -1) instead: in a traced run of the same cases, 2 of its 5 reloads never swapped in before the case ended, which is why it sits on top now.
  • NLEPreview.test.ts and useTimelinePlayer.shadowReload.test.ts: 91 tests, 3 runs, all pass. bun run typecheck clean; format, lint and fallow clean on the changed files.
  • fails without the fix: "keeps a reload's player out of clicks and focus until it is promoted, then gives them back" fails with the reload code's inert set removed, and again with its clear at promotion removed; "keeps a reload's preview out of sight, and a sealed one rendering (opaque)" fails on main's hidden, clipped style.

What I did NOT exercise

  • No macOS or Windows run, and no Safari or Firefox run.
  • A click during a reload is driven in the probe above, not in Studio itself.
  • Undo applying in place is fix(studio): an undo on a sealed preview shows in place, not after a reload #8009. With this change alone, whether an undo's reload has landed by the bench's first measure (about 70 ms after Ctrl+Z) is a race, so the bench's undo cell is not a measure of this change; the captures below are taken 1 s after Ctrl+Z.

Before

On main with the sealed default: the edit accuracy bench's root move case 1 s after Ctrl+Z. Studio already says "Undid: Move layer", but the box is still where the drag left it (the same spot as the committed drag), and the timeline clips have no thumbnails, because the reload has not swapped in yet.

Before: sealed preview on main, 1 s after Ctrl+Z, the box is still where the drag left it

After

This branch with the sealed default, same case and moment: the reload has swapped in, so the box is back where it started and the clips show their thumbnails.

After: sealed preview on this branch, 1 s after Ctrl+Z, the box is back

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 89 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (2)

  • seqplainkeys-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true
  • seqfastkeys-none-px-r0-root-z100: tracking 0.07, pressJump 0.05, drop 0, reload 0, render 0.02, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0.05, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0.05, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

…cks reach the live frame

Under the live frame (z-index -1) the reload's frame was left unpromoted in a traced run; on top and inert it renders and swaps in, and hit testing skips it, its own frame included.
…il it is promoted

Player keeps main's shape: the hook that owns the reload sets inert on the hidden frame's player element when its frame arrives and clears it at promotion.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE at 54d0567a

  • The sealing is unchanged.
    • Only CSS and inert change. There are no sandbox, CSP or messaging edits, and no new postMessage or port.
    • Each player still accepts only its own frame's messages.
    • The hidden frame still gets no shortcuts or audio state until promotion.
  • Root cause confirmed. Chrome stopped painting the hidden, clipped cross-origin frame. So its assets never reported ready, and only the player's 8 s timeout (ASSETS_READY_TIMEOUT_MS) let the swap happen. With opacity: 0 the frame keeps painting, and the loading overlay is hidden too, since a child can't override its container's opacity.
  • inert is set and cleared safely.
    • It's set from the ref, which Player calls once, before the element joins the page.
    • It's cleared only on the single promotion path, which is also where the editing iframe is re-pointed.
    • At promotion React keeps the same element and swaps the ref. The ref's null call doesn't re-apply inert, so the live preview stays clickable.
    • A failed or replaced hidden frame is removed from the page.
  • Tests: ran NLEPreview.test.ts, the shadow-reload tests and src/player/hooks, 281/281 passing. Each of three mutations fails exactly the test it names: dropping the inert set, dropping the clear, and restoring the old hidden style for a sealed preview.
  • Hygiene: the commits are verified and signed. No version bump or release change.
  • Non-blocking: as the PR's "What I did NOT exercise" section says, the click fix is only probed outside Studio. A real Studio click during a sealed reload would close that gap.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅
Risk: low. During a reload, the hidden frame now paints at full rate on top of the live one, and inert covers that. The non-sealed path keeps its old style.

— Rames

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE at 33dcce60 (re-stamp of 54d0567a)

  • 54d0567a...33dcce60 is one verified commit that rewords a single test comment in useTimelinePlayer.shadowReload.test.ts (+1/-1). No code changed, so my review at 54d0567a stands.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅
Risk: low.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 9daa7e8 Nov 17, 2026
77 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-sealed-reload-renders branch November 17, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants